/**
 * @file     lengthOfLastWord.js
 * @brief    [58. 最后一个单词的长度](https://leetcode.cn/problems/length-of-last-word/solution/)
 * @author   Zhu
 * @date     2022-10-15 01:07
 */

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLastWord = function (s) {
    let cur = s.length;
    let len = 0;
    while (cur > 0) {
        cur--;
        if (s[cur] === ' ' && len === 0) continue;
        if (s[cur] === ' ') break;
        len++;
    }

    return len;
};
